<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <script src="https://unpkg.com/vue@3.2.21/dist/vue.global.js"></script>
    <script src="https://unpkg.com/vue-router@4.0.12/dist/vue-router.global.js"></script>
    <script src="https://minglie.gitee.io/ming_node_plugis/src/lib/ming_mock2.5.0.js"></script>
</head>
<body>

    <div id="root">

    </div>
</body>
</html>

<script>
    M.config={
        baseUrl: api=> "https://actiondev.langjie.com"+api,
        wxLoginAppid: 'wxce9ef487ddc74aa5',
        wxCallBackUrl:'https://actiondev.langjie.com'
    }

    app.get("/checkWxCode",async (req,res)=>{
        const code=req.params.code;
        console.log(req.params,"AAAAAAAA")
        let r= await M.request.get('/open/login/scanCode',{
            reloadUrl: true,
            code: code
        });
        if(r.code!=200){
           console.log(r)
        }
        res.send(r);
        //res.send(M.mockData["targetBurnDiskBySn"])
    })


</script>


<script >
    const Login={
        template: `<iframe
                key='loginIframe'
                title='loginIframe'
                style='width: 100%;height: 420px;border: none; marginTop: 112px'
                :src='src'
            frameBorder="0" />`,
        data() {
            return {
                src:""
            }
        },
        async mounted() {
            let {redirect_uri,...queryparams } =  M.urlParse(location.href)
            let queryUrl= M.urlStringify(queryparams);
            redirect_uri="/rootFileList"
            this.src='https://open.weixin.qq.com/connect/qrconnect?appid='+M.config.wxLoginAppid+'&redirect_uri=' + encodeURIComponent( M.config.wxCallBackUrl+ '/WeixinWebLogin.html#/checklogin?redirectUrl=' + redirect_uri+ '&'+queryUrl) + '&response_type=code&scope=snsapi_login#wechat_redirect'
        }
    }
    const CheckLogin={
        template: `<h1>我是checkLogin</h1>`,
        async mounted() {
            const {redirectUrl,...queryparams } =  M.urlParse(location.href)
            let queryUrl= M.urlStringify(queryparams);
            const code=M.getParameter("code");
            let r= await MIO.checkWxCode({code});
            M.gloable_state.userInfo=r.data;
            console.log(r,queryUrl)
            this.$router.push({ path: "index"})
        }
    }

    const Index={
        template: `<h1>Index {{this.$gloable_state.userInfo.nickname}}</h1>`,
        async mounted() {

        }
    }


</script>




<script  type="module" async>
    const {createApp,reactive}=Vue;
    const  { createRouter,createWebHashHistory} =VueRouter;
    const routes = [
        { path: '/', component: Login },
        { path: '/login', component: Login },
        { path: '/checklogin', component: CheckLogin },
        { path: '/index', component: Index },
    ];
    const router = createRouter({
        history: createWebHashHistory(),
        routes: routes
    })
    const vueApp= createApp({
        template:` <router-view></router-view>`,
    });
    const gloable_state = reactive({ userInfo:{nickname:"zs"}});
    vueApp.config.globalProperties.$gloable_state =gloable_state;
    //全局状态
    M.gloable_state=gloable_state;
    vueApp.use(router);
    vueApp.mount('#root');
    window.vueApp=vueApp;


</script>


